<?php

function productResize($path, $path_thumb, $path_medium, $name)
{

 list($width, $height) = getimagesize($path);
 list($width_medium, $height_medium) = getimagesize($path);
 list($width_thumb, $height_thumb) = getimagesize($path);

   //large
   if($width>600)
   $towidth=600;
   else
   $towidth=$width;
   if($height>500)
   $toheight=ceil(($height/$width)*600);
   else
   $toheight=$height;
   if($toheight>500)
   {
   $toheight=500;
   $towidth=ceil(($width/$height)*500);
   }
   
   //medium level
    if($width>200)
   $towidth_medium=200;
   else
   $towidth_medium=$width;
   if($height>150)
   $toheight_medium=ceil(($height/$width)*200);
   else
   $toheight_medium=$height;
   if($toheight_medium>150)
   {
   $toheight_medium=150;
   $towidth_medium=ceil(($width/$height)*150);
   }

   //thumb level
   $towidth_thumb=100;
   $toheight_thumb=ceil(($height_thumb/$width_thumb)*100);

   if($toheight_thumb>100)
   {
   $toheight_thumb=100;
   $towidth_thumb=ceil(($width_thumb/$height_thumb)*100);
   }

 $imageResized = imagecreatetruecolor($towidth, $toheight);
 $imageResized_medium = imagecreatetruecolor($towidth_medium, $toheight_medium);
 $imageResized_thumb = imagecreatetruecolor($towidth_thumb, $toheight_thumb);
 if (preg_match("/jpg|jpeg|pjpeg/",strtolower($name)))
	{
	$src_img=imagecreatefromjpeg($path);
	imagecopyresampled($imageResized,$src_img, 0, 0, 0, 0, $towidth, $toheight, $width, $height);
    imagecopyresampled($imageResized_medium,$src_img, 0, 0, 0, 0, $towidth_medium, $toheight_medium, $width_medium, $height_medium);
	imagecopyresampled($imageResized_thumb,$src_img, 0, 0, 0, 0, $towidth_thumb, $toheight_thumb, $width_thumb, $height_thumb);
	ImageJpeg($imageResized,$path,100);
    ImageJpeg($imageResized_medium,$path_medium,100);
	ImageJpeg($imageResized_thumb,$path_thumb,100);
	}
if (preg_match("/png/",strtolower($name)))
	{
	$src_img=imagecreatefrompng($path);
	imagecopyresampled($imageResized,$src_img, 0, 0, 0, 0, $towidth, $toheight, $width, $height);
	imagecopyresampled($imageResized_medium,$src_img, 0, 0, 0, 0, $towidth_medium, $toheight_medium, $width_medium, $height_medium);
	imagecopyresampled($imageResized_thumb,$src_img, 0, 0, 0, 0, $towidth_thumb, $toheight_thumb, $width_thumb, $height_thumb);
	ImageJpeg($imageResized,$path,100);
	ImageJpeg($imageResized_medium,$path_medium,100);
	ImageJpeg($imageResized_thumb,$path_thumb,100);
	}

if (preg_match("/gif/",strtolower($name)))
	{
	$src_img=imagecreatefromgif($path);
	imagecopyresampled($imageResized,$src_img, 0, 0, 0, 0, $towidth, $toheight, $width, $height);
	imagecopyresampled($imageResized_medium,$src_img, 0, 0, 0, 0, $towidth_medium, $toheight_medium, $width_medium, $height_medium);
	imagecopyresampled($imageResized_thumb,$src_img, 0, 0, 0, 0, $towidth_thumb, $toheight_thumb, $width_thumb, $height_thumb);
	ImageJpeg($imageResized,$path,100);
	ImageJpeg($imageResized_medium,$path_medium,100);
	ImageJpeg($imageResized_thumb,$path_thumb,100);
	}
}	


?>